#!/bin/sh

if test x"$srcdir" != x""; then
    builddir="."	# running from make check, but it does not define that
else
    srcdir=`echo "$0" | sed s,[^/]*$,,`
    test "$srcdir" = "$0" && srcdir=.
    test -z "$srcdir" && srcdir=.
    builddir="$srcdir"	# running manually, have to assume
fi

srcdir=`cd $srcdir;pwd`
builddir=`cd $builddir;pwd`

basedir=".."
cd $srcdir; if [ ! -d $basedir -o ! -f $basedir/src/dtsdec.c -o \
    ! -f $basedir/dtsdec-*.tar.gz ]; then
    cd ..; if [ ! -d $basedir -o ! -f $basedir/src/dtsdec.c -o \
	! -f $basedir/dtsdec-*.tar.gz ]; then
	exit 77
    fi
fi
basedir=`cd $basedir;pwd`

cd $builddir
rm -fr compile_test

for compiler in cc gcc gcc272 gcc-2.95 gcc-3.0 gcc-3.1 gcc-3.2 c89 \
		c++ g++ g++-2.95 g++-3.0 g++-3.1 g++-3.2 \
		ccmalloc-gcc bgcc checkergcc tendracc icc \
		tcc-noexec tcc-bounds i586-mingw32msvc-gcc; do
    compiler_path=`which $compiler`
    if test x"$compiler_path" = x""; then continue; fi

    mkdir compile_test
    cd compile_test; tar xzpf $basedir/dtsdec-*.tar.gz; cd dtsdec-*
    case "$compiler" in
	i586-mingw32msvc-gcc)
			opts="--host=i586-mingw32msvc --enable-warnings";;
	ccmalloc-gcc)	opts="--enable-warnings --enable-debug";;
	tcc-*)		opts="--enable-warnings --disable-oss";;
	*)		opts="--enable-warnings";;
    esac
    error=1; CC=$compiler ./configure $opts && make && error=0
    if test x"$error" != x"0"; then exit 1; fi
    error=1; CC=$compiler ./configure $opts --enable-fixed && make && error=0
    if test x"$error" != x"0"; then exit 1; fi
    cd ../..
    rm -fr compile_test
done

exit 0
